//子弹
function Bullet({
    width,
    height,
    x,
    y,
    img,
    speed
}) {
    Role.call(this, {
        width,
        height,
        x,
        y
    });
    this.img = img;
    this.speed = speed;
    //创建DOM元素
    this.createDom();
}
//原型链继承
Bullet.prototype = Object.create(Role.prototype);

//创建DOM元素
Bullet.prototype.createDom = function () {
    //创建DOM元素节点
    this.element = document.createElement("div");
    //设置CSS属性
    this.element.style.width = this.width + "px";
    this.element.style.height = this.height + "px";
    this.element.style.background = `url(${this.img})`;
    this.element.style.position = "absolute";
    this.element.style.left = this.x + "px";
    this.element.style.top =
        this.y + "px";
    //将dom节点添加到地图中
    Map.addRole(this);
}
//重写Go方法
Bullet.prototype.go = function () {
    if (!this.isAlive) //如过已经消失，就不再继续移动了
        return;
    //移动过程中,Y坐标更改
    this.y += this.speed;
    //判断是否超出地图范围
    if (this.y <= -10) {
        this.isAlive = false; //标记当前子弹是否存在
        this.element.parentNode.removeChild(this.element);
        return
    }
    //修改css
    this.element.style.top = this.y + "px";
}